package site.yunnong.atvris.service.helper;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import site.yunnong.atvris.common.utils.DateUtils;
import site.yunnong.atvris.dao.domain.User;
import site.yunnong.atvris.dao.domain.UserProfile;
import site.yunnong.atvris.dao.domain.Video;
import site.yunnong.atvris.dao.domain.VideoProfile;
import site.yunnong.atvris.dao.domain.ext.VideoDetail;
import site.yunnong.atvris.service.vo.UserInfoVO;
import site.yunnong.atvris.service.vo.VideoCardVO;
import site.yunnong.atvris.service.vo.VideoDetailsVO;

/**
 * @author zjh
 * @date 2021/9/7 12:13
 */
@Slf4j
public class BuildHelper {

    public static VideoDetailsVO buildVideoDetailsVO(Video video, VideoProfile videoProfile) {
        VideoDetailsVO vo = new VideoDetailsVO();
        BeanUtils.copyProperties(video, vo);
        vo.setDuration(DateUtils.covertSecondToDuration(video.getVideoTime()));
        BeanUtils.copyProperties(videoProfile, vo);
        return vo;
    }

    public static UserInfoVO buildUserInfoVO(User user, UserProfile profile) {
        UserInfoVO vo = new UserInfoVO();
        BeanUtils.copyProperties(user, vo);
        if (profile == null) {
            profile = new UserProfile();
            log.error("数据异常，未获取到指定uuid的user profile, uuid:{}", user.getUuid());
        }
        BeanUtils.copyProperties(profile, vo);
        return vo;
    }

    public static VideoCardVO buildVideoCardVO(VideoDetail videoDetail) {
        VideoCardVO vo = new VideoCardVO();
        BeanUtils.copyProperties(videoDetail, vo);
        vo.setDuration(DateUtils.covertSecondToDuration(videoDetail.getVideoTime()));
        return vo;
    }
}
